/*
 * AttackView.cpp
 *
 *  Created on: 24/01/2011
 *      Author: Nenem
 */

#include "AttackView.h"
#include <iostream>
using namespace std;

AttackView::AttackView() {
	time = 0;
	done = false;
	i = 0;
	image = NULL;
}

AttackView::~AttackView() {
	if(image != NULL){
		delete image;
	}
}

void AttackView::update(int delta, Model *model, Graphics *graphics){
	time+=delta;

	image->update(model->direction, model->position);

	if(model->battle->getAttack()->getAttackSpeed() * (time - delta) > 1000){
		time = delta;
		i++;
		if(image->getFrameAtual() < image->getN_frames()){
			image->changeFrame();
		}
		else{
			if(i > image->getN_frames()){
				done = true;
			}
		}
	}

	graphics->sprites.push_back(image);
}

void AttackView::setFrameRate(int frameRate){
	this->frameRate = frameRate;
}

Image *AttackView::getImage(){
	return image;
}

void AttackView::setImage(Image *image){
	this->image = image;
}
